package com.atguigu.boot3.ssm.mapper;

import com.atguigu.boot3.ssm.bean.TUser;
import com.atguigu.boot3.ssm.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lfy
 * @Description
 * @create 2023-04-20 16:59
 */
@Mapper
public interface UserMapper {

    /**
     * 1、每个方法都在Mapper文件中有一个sql标签对应。
     * 2、所有参数都应该用@Param进行签名，以后使用指定的名字在SQL中取值
     * @param id
     * @return
     */
    TUser getUserById(@Param("id") Long id);

    @Select("SELECT * FROM sys_name")
    List<User> findAll();

    //查询by Id
    @Select("SELECT * FROM sys_name WHERE where id=#{id}")
    List<User> findById(@Param("id") Integer id);

    //增加
    @Insert("INSERT INTO sys_name (username, password, position, email, phone, address) " +
            "VALUES (#{username}, #{password}, #{position}, #{email}, #{phone}, #{address})")
    int insert(User user);
    //修改
    @Update("UPDATE sys_name " +
            "SET username=#{username}, password=#{password}, position=#{position}, " +
            "email=#{email}, phone=#{phone}, address=#{address} " +
            "WHERE id=#{id}")
    int update(User user);
    //删除
    @Delete("delete from sys_name where id=#{id}")
    Integer delectById(@Param("id") Integer id);

}
